package gw.com.android.ui.account;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;

import com.gwtsz.gts2.hx.R;

import gw.com.android.model.ConfigSettingDeal;
import gw.com.android.model.ConfigType;
import gw.com.android.model.ConfigUtil;
import gw.com.android.ui.BaseActivity;
import gw.com.android.ui.WebFragment;
import gw.com.android.ui.WebPageActivity;
import gw.com.android.ui.dialog.AssistantDialog;
import www.com.library.app.FragmentsManagerUtil;
import www.com.library.view.BtnClickListener;

/**
 * Created by reeta.zou on 2017/5/4.
 * 开户界面
 */

public class OpenAccountActivity extends BaseActivity {

    private WebFragment mRealOpenFragment;
    private WebFragment mDemoOpenFragment;

    @Override
    protected int getLayoutView() {
        return R.layout.activity_open_account;
    }

    @Override
    protected void initLayoutView() {
        String title = getIntent().getStringExtra("title");
        if (TextUtils.isEmpty(title)) {
            mTitleBar.setAppTitle(R.string.quote_title_open);
        } else {
            mTitleBar.setAppTitle(title);
        }
//        mTitleBar.setBtnClickListener(new BtnClickListener() {// 为什么这个click事件没有被触发?
//            @Override
//            public void onBtnClick(int viewID) {
//                if (viewID == R.id.title_left_icon) {
//                    onBackPressed();
//                }
//            }
//        });
        String fromType = getIntent().getStringExtra("fromType");
        if (ConfigType.ADD_LOGIN_DEMO_TAG.equals(fromType)) {
            showDemoOpenFragment();
        } else {
            showRealOpenFragment();
        }
//        new AssistantDialog().attach(this, mTitleBar, AssistantDialog.REGISTER);

        mTitleBar.setRightIcon(R.mipmap.a_nav_service_b);
        mTitleBar.setBtnClickListener(new BtnClickListener() {
            @Override
            public void onBtnClick(int viewID) {
                Log.d("viewIDTag", "" + R.id.title_left_icon + "- " + viewID);
                if (viewID == R.id.title_left_icon) {
                    onBackPressed();
                } else if (viewID == R.id.title_right_icon) {
                    ConfigSettingDeal mDeal = new ConfigSettingDeal();
                    mDeal.openQQ(OpenAccountActivity.this, ConfigType.QQ_SOURCE_LOGIN);
                }
            }
        });
    }

    @Override
    protected void initViewData() {

    }

    /**
     * 展示开立真实账号界面
     */
    public void showRealOpenFragment() {
        mCurrentTag = ConfigType.ADD_LOGIN_REAL_TAG;
        mRealOpenFragment = (WebFragment) FragmentsManagerUtil.instance().getFragmentbyTag(OpenAccountActivity.this, mCurrentTag);
        if (null == mRealOpenFragment) {
            mRealOpenFragment = new WebFragment();
            Bundle bundle = new Bundle();
            bundle.putString("url", ConfigUtil.instance().getUrlPath(mCurrentTag));
            bundle.putString(ConfigType.CONFIG_TYPE_KEY_TAG, mCurrentTag);
            mRealOpenFragment.setArguments(bundle);
            FragmentsManagerUtil.instance().addPushMsgTabFragment(OpenAccountActivity.this, mRealOpenFragment, mCurrentTag);
        }
        showFragment(mRealOpenFragment);
    }

    /**
     * 展示开立模拟账号界面
     */
    public void showDemoOpenFragment() {
        mCurrentTag = ConfigType.ADD_LOGIN_DEMO_TAG;
        mDemoOpenFragment = (WebFragment) FragmentsManagerUtil.instance().getFragmentbyTag(OpenAccountActivity.this, mCurrentTag);
        if (null == mDemoOpenFragment) {
            mDemoOpenFragment = new WebFragment();
            Bundle bundle = new Bundle();
            bundle.putString("url", ConfigUtil.instance().getUrlPath(mCurrentTag));
            bundle.putString(ConfigType.CONFIG_TYPE_KEY_TAG, mCurrentTag);
            mDemoOpenFragment.setArguments(bundle);
            FragmentsManagerUtil.instance().addPushMsgTabFragment(OpenAccountActivity.this, mDemoOpenFragment, mCurrentTag);
        }
        showFragment(mDemoOpenFragment);
    }

    /**
     * 重新该类，什么都不做，开户界面不显示福利小弹窗的广告哟~~
     */
    @Override
    public void showNoviceWelfare(String title, String link) {
    }

    @Override
    public void onBackPressed() {
        if (mRealOpenFragment != null && mRealOpenFragment.onBackPressed()) {
            return;
        }
        if (mDemoOpenFragment != null && mDemoOpenFragment.onBackPressed()) {
            return;
        }
        super.onBackPressed();
    }

}
